package com.ftg.learn.bus.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.entity.BusInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 公车信息表 Mapper 接口
 * </p>
 *
 * @author lalala
 * @since 2022-03-07
 */
public interface BusInfoMapper extends BaseMapper<BusInfo> {

    /**
     * 查询所有车的信息及其负责人信息
     */
    @Select("select a.*,b.dname,b.dphone from sys_bus_info as a left join sys_director as b on a.did = b.did")
    List<Map<String,Object>> showBusInfoDirector();


    /**
     * 根据车的信息查询负责人信息
     * @param bid 车id
     * @return data
     */
    @Select("select b.did, b.dname,b.dphone from sys_bus_info as a left join sys_director as b on a.did = b.did where bid = #{bid}")
    List<Map<String,Object>> showDirectorForBid(@Param("bid") Long bid);


    /**
     * 查询
     * @param bid bid
     * @return
     */
    @Select("select * from sys_bus_info where bid = #{bid}")
    List<BusInfo> showByBid(@Param("bid") Long bid);


    @Select("select * from sys_bus_info where bid = #{bid}")
    List<BusInfo> pageInfoByName(Page<BusInfo> page,Long bid);

    /**
     * 简单展示
     * @return
     */
    @Select("select bus_name,bus_no,receiver,unit,park,category,purpose,manufacturer from sys_bus_info")
    List<BusInfo> showSimple(Page<BusInfo> infoPage);

    /**
     * 显示所有负责人 id
     * @return
     */
    @Select("select did,dname from sys_director where status = 0")
    List<Map<String,Object>> showAllDName();

    /**
     * 修改时间
     * @param bid bid
     * @return
     */
    @Update("update sys_bus_info set update_time = now() where bid = #{bid}")
    boolean updateTimeByBid(@Param("bid") Long bid);

}
